package com.ldk.base.framework.datasource.generator;

import com.ldk.base.framework.datasource.DataSourceDriver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.List;




/**
 * db2表实体生成器
 * @author xiangwl
 *
 */
public class DB2EntityGenerator extends EntityGenerator {
	/**
	 * 构造函数
	 * @param serverName
	 * @param portNumber
	 * @param databaseName
	 * @param user
	 * @param password
	 */
	public DB2EntityGenerator(String serverName, int portNumber, String databaseName, String user, String password){
		setServerName(serverName);
		setPortNumber(portNumber);
		setDatabaseName(databaseName);
		setUser(user);
		setPassword(password);
	}
	
	@Override
	protected List<String> getTables() {
		return null;
	}

	@Override
	protected List<TableColumn> getTableColums(String table) {
		return null;
	}

	@Override
	public Connection getConnection() {
		// jdbc:db2://localhost:50000/toolsdb
		String url = String.format("jdbc:db2://%s:%d/%s",
				getServerName(), getPortNumber(), getDatabaseName());
		Connection conn = null;
		try {
			Class.forName(DataSourceDriver.DB2.getNoXADriver());
			conn = DriverManager.getConnection(url, getUser(), getPassword());
		} catch (Exception e) {

		}
		return conn;
	}

	@Override
	protected DBType getDbType() {
		return DBType.DB2;
	}

}
